#include "promptview.h"
#include "item/imageitem.h"
#include "recource.h"
#include <QLocale>

enum PromptBtn
{
    YES_PB,
    NO_PB,
    NULL_PB,
}promptBtn(NULL_PB);

PromptView::PromptView(QWidget *parent,int type) :
    QGraphicsView(parent),m_Type(type)
{
    m_Scene = new QGraphicsScene(this);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setScene(m_Scene);
    m_Scene->setSceneRect(0.0, 0.0, 360.0, 640.0);
    setGeometry(0.0,0.0,360.0,640.0);

    m_bgItem = new ImageItem(*Recource::m_promptbgImage,
                             QRect(QPoint(0,0),Recource::m_promptbgImage->size()));
    m_bgItem->setPos(0.0,0.0);
    m_bgItem->setZValue(0.0);
    m_Scene->addItem(m_bgItem);
    if(m_Type==0)
    {
        switch(Recource::m_iLanguage)
        {
        case QLocale::Chinese:
        {
            m_mbgItem = new ImageItem(*Recource::m_promptmbgImage,
                                     QRect(QPoint(0,0),Recource::m_promptmbgImage->size()));
            m_yesItem = new ImageItem(*Recource::m_promptYesImage,
                                     QRect(QPoint(0,0),Recource::m_promptYesImage->size()));
            m_yesItem->setPos(67.0,353.0);
            m_noItem = new ImageItem(*Recource::m_promptNoImage,
                                     QRect(QPoint(0,0),Recource::m_promptNoImage->size()));
            m_noItem->setPos(229.0,353.0);
        }
            break;
    //    case QLocale::HongKong:
        case 255:
        {
            m_mbgItem = new ImageItem(*Recource::m_promptmbgHkImage,
                                     QRect(QPoint(0,0),Recource::m_promptmbgHkImage->size()));
            m_yesItem = new ImageItem(*Recource::m_promptYesImage,
                                     QRect(QPoint(0,0),Recource::m_promptYesImage->size()));
            m_yesItem->setPos(67.0,353.0);
            m_noItem = new ImageItem(*Recource::m_promptNoImage,
                                     QRect(QPoint(0,0),Recource::m_promptNoImage->size()));
            m_noItem->setPos(229.0,353.0);
        }
            break;
        default:
        {
            m_mbgItem = new ImageItem(*Recource::m_promptmbgEnImage,
                                     QRect(QPoint(0,0),Recource::m_promptmbgEnImage->size()));
            m_yesItem = new ImageItem(*Recource::m_promptYesEnImage,
                                     QRect(QPoint(0,0),Recource::m_promptYesEnImage->size()));
            m_yesItem->setPos(57.0,360.0);
            m_noItem = new ImageItem(*Recource::m_promptNoEnImage,
                                     QRect(QPoint(0,0),Recource::m_promptNoEnImage->size()));
            m_noItem->setPos(213.0,354.0);
        }
            break;
        }
    }else
    {
        qWarning("1");
        switch(Recource::m_iLanguage)
        {
        case QLocale::Chinese:
        {
            m_mbgItem = new ImageItem(*Recource::m_promptmbgImage_new_cn,
                                     QRect(QPoint(0,0),Recource::m_promptmbgImage_new_cn->size()));
            m_yesItem = new ImageItem(*Recource::m_promptYesImage,
                                     QRect(QPoint(0,0),Recource::m_promptYesImage->size()));
            m_yesItem->setPos(67.0,353.0);
            m_noItem = new ImageItem(*Recource::m_promptNoImage,
                                     QRect(QPoint(0,0),Recource::m_promptNoImage->size()));
            m_noItem->setPos(229.0,353.0);
        }
            break;
    //    case QLocale::HongKong:
        case 255:
        {
            m_mbgItem = new ImageItem(*Recource::m_promptmbgImage_new,
                                     QRect(QPoint(0,0),Recource::m_promptmbgImage_new->size()));
            m_yesItem = new ImageItem(*Recource::m_promptYesImage,
                                     QRect(QPoint(0,0),Recource::m_promptYesImage->size()));
            m_yesItem->setPos(67.0,353.0);
            m_noItem = new ImageItem(*Recource::m_promptNoImage,
                                     QRect(QPoint(0,0),Recource::m_promptNoImage->size()));
            m_noItem->setPos(229.0,353.0);
        }
            break;
        default:
        {
            m_mbgItem = new ImageItem(*Recource::m_promptmbgEnImage,
                                     QRect(QPoint(0,0),Recource::m_promptmbgEnImage->size()));
            m_yesItem = new ImageItem(*Recource::m_promptYesEnImage,
                                     QRect(QPoint(0,0),Recource::m_promptYesEnImage->size()));
            m_yesItem->setPos(57.0,360.0);
            m_noItem = new ImageItem(*Recource::m_promptNoEnImage,
                                     QRect(QPoint(0,0),Recource::m_promptNoEnImage->size()));
            m_noItem->setPos(213.0,354.0);
        }
            break;
        }
    }

    m_mbgItem->setPos(0.0,159.0);
    m_mbgItem->setZValue(1.0);
    m_Scene->addItem(m_mbgItem);

    m_yesItem->setZValue(2.0);
    m_yesItem->setVisible(false);
    m_Scene->addItem(m_yesItem);

    m_noItem->setZValue(2.0);
    m_noItem->setVisible(false);
    m_Scene->addItem(m_noItem);
}

PromptView::~PromptView()
{
    delete m_Scene;
}

void PromptView::mousePressEvent(QMouseEvent *event)
{
    if(m_yesItem->isUnderMouse())
    {
        m_yesItem->setVisible(true);
        promptBtn = YES_PB;
    }
    else if(m_noItem->isUnderMouse())
    {
        m_noItem->setVisible(true);
        promptBtn = NO_PB;
    }else
    {
        promptBtn = NULL_PB;
    }
}

void PromptView::mouseReleaseEvent(QMouseEvent *event)
{
    switch(promptBtn)
    {
    case YES_PB:
    {
        m_yesItem->setVisible(false);
        if(m_yesItem->isUnderMouse())
        {
           emit back(1);
        }
    }
        break;
    case NO_PB:
    {
        m_noItem->setVisible(false);
        if(m_noItem->isUnderMouse())
        {
            emit back(0);
        }
    }
        break;
    default:
        break;
    }
}
